package com.parenting.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.parenting.entities.ParentingRuleDO;
import com.parenting.request.platform.SaveOrUpdateRule;
import com.parenting.response.platform.RuleResponse;
import com.parenting.service.ParentingRuleService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 规则设置  前端控制器
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-10-18
 */
@RestController
@Api(tags = "规则管理")
@RequestMapping("/parentingRuleDO")
public class ParentingRuleController {

    @Autowired
    private ParentingRuleService parentingRuleService;


    @ApiOperation("新增或修改规则，传入ID 为修改，不传入ID 为新增")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdateRule(@RequestBody SaveOrUpdateRule rule){
        parentingRuleService.saveOrUpdateRule(rule);
        return Result.buildSuccess();
    }

    @ApiOperation("查询当前设置的规则")
    @GetMapping("rule")
    public Result<RuleResponse> getRuleOne(){
        ParentingRuleDO one = parentingRuleService.getOne(new LambdaQueryWrapper<>());
        RuleResponse ruleResponse = BeanUtil.copyProperties(one, RuleResponse.class);
        return Result.buildSuccess(ruleResponse);
    }

}

